import pymysql

try:
    # 连接到MySQL服务器
    conn = pymysql.connect(
        host='localhost',
        port=3306,
        user='root',
        password='1234',
        charset='utf8mb4'
    )
    
    cursor = conn.cursor()
    
    # 创建数据库
    cursor.execute("CREATE DATABASE IF NOT EXISTS management_system CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
    print("数据库 'management_system' 创建成功")
    
    conn.close()
    
except Exception as e:
    print(f"创建数据库失败: {e}")
